//
//  AXFPayViewController.m
//  AIXF
//
//  Created by Macx on 2017/7/13.
//  Copyright © 2017年 Macx. All rights reserved.
//

#import "AXFPayViewController.h"
#import "AXFPayBottomTableViewCell.h"
#import "AXTotalPriceFTableViewCell.h"
#import "AXFSurePayView.h"
#import <Masonry.h>
@interface AXFPayViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong)UITableView *tableView;
@end

static NSString *topCell = @"topCell";
static NSString *middleCell = @"middleCell";
static NSString *goodCell = @"goodCell";
static NSString *totalPriceCell = @"totalPrice";
@implementation AXFPayViewController

- (void)setModelArray:(NSArray *)modelArray
{
    _modelArray = modelArray;
    
    [self.tableView reloadData];
    
    UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
    _tableView = tableView;
    
    [self.view addSubview:tableView];
    
    tableView.delegate = self;
    
    tableView.dataSource = self;
    
    [tableView registerNib:[UINib nibWithNibName:@"AXFPayMiddleTableViewCell" bundle:nil] forCellReuseIdentifier:middleCell];
    [tableView registerNib:[UINib nibWithNibName:@"AXFPayBottomTableViewCell" bundle:nil] forCellReuseIdentifier:goodCell];
    [tableView registerNib:[UINib nibWithNibName:@"AXFTopTableViewCell" bundle:nil] forCellReuseIdentifier:topCell];
    [tableView registerNib:[UINib nibWithNibName:@"AXTotalPriceFTableViewCell" bundle:nil] forCellReuseIdentifier:totalPriceCell];
    
    AXFSurePayView *surePay = [AXFSurePayView new];
    [self.view addSubview:surePay];
    
    [surePay mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(self.view);
        make.height.offset(60);
    }];
    
    self.navigationItem.title = @"结算付款";
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CGFloat height = 0;
    
    switch (indexPath.section) {
        case 0:
            height = 44;
            break;
        case 1:
            height = 244;
            break;
        case 2:
            height = 44;
            break;
        case 3:
            height = 150;
            break;
    }
    return height;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 4;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 2)
    {
        return self.modelArray.count;
    }
    
    return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell;

    if (indexPath.section == 0)
    {
        cell = [tableView dequeueReusableCellWithIdentifier:topCell forIndexPath:indexPath];
    }
    if (indexPath.section == 1)
    {
        cell = [tableView dequeueReusableCellWithIdentifier:middleCell forIndexPath:indexPath];
    }
    if (indexPath.section == 2)
    {
       AXFPayBottomTableViewCell *cell = (AXFPayBottomTableViewCell *)[tableView dequeueReusableCellWithIdentifier:goodCell forIndexPath:indexPath];
        cell.model =  self.modelArray[indexPath.row];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
    if (indexPath.section == 3)
    {
        cell = [tableView dequeueReusableCellWithIdentifier:totalPriceCell forIndexPath:indexPath];
    }
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
}



@end
